const { ChildProcess } = require('child_process');
const fs = require('fs');
const path = require('path');
const color = require('colors');

function removeNodeModulesShbLib() {
  
  
  const shbLibPath = path.resolve(__dirname, '../node_modules/@shb-lib');
  
  if (fs.existsSync(shbLibPath)) {
    fs.rmdirSync(shbLibPath, { recursive: true });
  }
  
}

function removeVueDeptsShbLib() {
  
  
  const depsPath = path.resolve(__dirname, '../node_modules/.vite/deps');
  const shbLibPackages = fs.readdirSync(depsPath).filter((item) => item.startsWith('@shb-lib'));
  
  shbLibPackages.forEach((shbLibPackage) => {
    
    const shbLibPackagePath = path.resolve(depsPath, shbLibPackage);
    
    if (fs.existsSync(shbLibPackagePath)) {
      fs.rmSync(shbLibPackagePath, { recursive: true });
    }
    
  });
  
}

function main() {
  
  removeNodeModulesShbLib();
  removeVueDeptsShbLib();
  
  console.log(
    color.green('Removed shb-lib dependencies successfully!')
  );
  
}

main();